﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <link href="../CSS/Style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/Style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        function date2str(date) {
            //null判断
            if (date == null) return "";
            //去掉左右的斜杠
            date = date.replace(/\//g, "");
            //将其转为一个日期对象
            eval("var d = new " + date + ";");
            //返回最终结果
            return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
        }
        function Load() {
            $(".dataTable tr:gt(0)").live("click", function () {
                $(".dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "yellow");
                $("#dataDiv div:first").css("background-image", "url(../images/bg.gif)");
                $("#dataDiv div:last").css("background-image", "url()");
            });
        }

        var pageSize = 3;
        var pageIndex = 1;
        var pageCount = 1;

        function reloadList() {
            
            if (pageIndex < 1)
                pageIndex = 1;
            if (pageIndex > pageCount)
                pageIndex = pageCount;
            $.get("saleManager.ashx", {
                action: "paging",
                pageIndex: pageIndex,
                pageSize: pageSize
            }, function (result) {
                var r = JSON.parse(result);
                pageCount = parseInt((r.total - 1) / pageSize) + 1;
                $("#leftPage").text("共有" + r.total + "条记录，第" + pageIndex + "页/共" + pageCount + "页");
                $("#tb1 tr:gt(0)").remove();
                var tb1 = $("#tb1").get(0);
                for (var i = 0; i < r.data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = r.data[i].ChanName || '';
                    tr.insertCell(-1).innerHTML = r.data[i].ChanTitle || '';
                    tr.insertCell(-1).innerHTML = r.data[i].ChanLinkMan || '';
                    tr.insertCell(-1).innerHTML = r.data[i].ChanLinkTel || '';
                    tr.insertCell(-1).innerHTML = date2str(r.data[i].ChanCreateDate || '');
                    tr.insertCell(-1).innerHTML = r.data[i].StateString || '';
                    tr.insertCell(-1).innerHTML = '<img title="查看" src="../images/bt_' + r.data[i].ChanState + '.gif" onclick="edit(' + r.data[i].ChanID + ')"/>';

                }
            });
        }

        $(function () {
            Load();
            reloadList();

            $("#a1").click(function () {
                pageIndex = 1;
                reloadList();
            });
            $("#a2").click(function () {
                pageIndex--;
                reloadList();
            });
            $("#a3").click(function () {
                pageIndex++;
                reloadList();
            });
            $("#a4").click(function () {
                pageIndex = pageCount;
                reloadList();
            });
            $("#a5").click(function () {
                var a1 = $("#a6").val();
                if (a1 <= pageCount) {
                    pageIndex = a1;
                    reloadList();

                }
            });

        })

        function showOK(id) {
            
            $.showModalDialog("SaleOk.htm?data=" + Math.random(), { id: id }, 600, 300, function (r) {
                if (r) {
                    reloadList();
                }
            });
        }

        function showNo(id) {
            
            $.showModalDialog("SaleNo.htm?data=" + Math.random(), { id: id }, 600, 300, function (r) {
                if (r) {
                    reloadList();
                }
            });
        };

        function showOpen(id) {
            
            $.showModalDialog("SaleOpen.htm?data=" + Math.random(), { id: id }, 600, 300, function (r) {
                if (r) {
                    reloadList();
                }
            });
        }

        function edit(id) {
            //通过id将资料从数据库中查询出来
            $.get("saleManager.ashx", { action: "byid", id: id }, function (r) {
                //转为js对象
                var c = JSON.parse(r);
                if (c != null) {
                    if (c.ChanState == 2) {
                        showOpen(id);
                    }
                    else if (c.ChanState == 3) {
                        showOK(id);
                    }
                    else if (c.ChanState == 4) {
                        showNo(id);
                    }
                }
            });
        }
        
    </script>
</head>
<body>
<div id="desDiv">
    <span>客户开发计划</span><br />
    制定客户开发计划和记录开发进度
</div>

<br />
<div id="dataDiv">
    <div id="headDivw">
    </div>
    <table class="dataTable" id="tb1">
        <tr>
            <th align="center">客户名称</th>
            <th align="center">概要</th>
            <th align="center">联系人</th>
            <th align="center">联系电话</th>
            <th align="center">创建时间</th>
            <th align="center">状态</th>
            <th align="center">操作</th>
        </tr>
    </table>
    <div id="pageDiv">
        <div id="leftPage">共有10条记录，当前第1/5页</div>
        <div id="rightPage">
            <input type="image" src="../images/first.gif" id="a1" />&nbsp;&nbsp;
            <input type="image" src="../images/back.gif" id="a2" />&nbsp;&nbsp;
            <input type="image" src="../images/next.gif" id="a3" />&nbsp;&nbsp;
            <input type="image" src="../images/last.gif" id="a4" />&nbsp;&nbsp;
            转到第<input type="text" id="a5" size="2" />&nbsp;&nbsp;<input type="image" src="../images/go.gif" onclick="turn();" />
        </div>
    </div>
</div>
</body>
</html>